﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Formboard
{
	public partial class Login : UserControl
	{
		public Login ()
		{
			InitializeComponent ();
			passwordBox.UseSystemPasswordChar = true;
		}

		private void Login_Load (object sender, EventArgs e)
		{

		}

		private void buttonCreateUser_Click (object sender, EventArgs e)
		{
			if (!((Form1)this.Parent).requesterChecked) {
				((Form1)this.Parent).requester = new HttpRequestProvider (textBoxIP.Text, textBoxPort.Text);
				((Form1)this.Parent).requester.getConfiguration ();
				((Form1)this.Parent).requesterChecked = true;
			}
			((Form1)this.Parent).goto_accountcreation ();
		}


		/*
         * checkfields checks Username and passwords fields
         * returns 0 if ok, 1 if a field is missing
         */
		int checkFields ()
		{
			if ((usernameBox.Text.Length == 0) || (passwordBox.Text.Length == 0)) {
				return 1;
			} else {
				return 0;
			}
		}

		private void buttonSignin_Click (object sender, EventArgs e)
		{
			if (!((Form1)this.Parent).requesterChecked) {
				((Form1)this.Parent).requester = new HttpRequestProvider (textBoxIP.Text, textBoxPort.Text);
				((Form1)this.Parent).requester.getConfiguration ();
				((Form1)this.Parent).requesterChecked = true;
			}
			int fields = checkFields ();
			if (fields == 0) {
				Params.Parameters.name = usernameBox.Text;
				Params.Parameters.password = passwordBox.Text;  
			}
			((Form1)this.Parent).myscreenname = usernameBox.Text;
			((Form1)this.Parent).goto_gameLaucher_from_login ();
		}

		private void label1_Click (object sender, EventArgs e)
		{

		}
	}
}
